//*********************************************************
//
//    Copyright (c) Microsoft. All rights reserved.
//    This code is licensed under the Apache License, Version 2.0.
//    THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
//    ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
//    IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
//    PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//********************************************************* 

using System;
using System.Xml.Serialization;

namespace Microsoft.TridentWordAddIn.Common
{
    public enum ConnectionOperation
    {
        Added,
        Edited,
        Deleted,
        Changed
    }

    /// <summary>
    /// Connection configuration properties for accessing a Trident server
    /// </summary>
    [Serializable]
    public class TridentConnection : DomainBase
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="TridentConnection"/> class.
        /// </summary>
        public TridentConnection() { }

        /// <summary>
        /// Gets or sets a value indicating whether [need password save].
        /// </summary>
        /// <value><c>true</c> if [need password save]; otherwise, <c>false</c>.</value>
        [XmlIgnore]
        public bool NeedCredentialSave { get; set; }

        /// <summary>
        /// Gets or sets the name of the source.
        /// </summary>
        /// <value>The name of the source.</value>
        public string SourceName { get; set; }

        /// <summary>
        /// Gets or sets the type of the conn.
        /// </summary>
        /// <value>The type of the conn.</value>
        public ConnectionType ConnectionType { get; set; }

        /// <summary>
        /// Gets or sets the name of the connection.
        /// </summary>
        /// <value>The name of the connection.</value>
        public string Name { get; set; }

        /// <summary>
        /// Gets or sets the SQL connection parameters.
        /// </summary>
        /// <value>The SQL connection parameters.</value>
        public TridentSqlConnectionParameters SqlParameters { get; set; }

        /// <summary>
        /// Gets or sets the sitka connection parameters.
        /// </summary>
        /// <value>The sitka connection parameters.</value>
        public TridentSitkaConnectionParameters SitkaParameters { get; set; }

        /// <summary>
        /// Gets or sets the web service connection parameters.
        /// </summary>
        /// <value>The web service connection parameters.</value>
        public TridentWebServiceConnectionParameters AmazonParameters { get; set; }

        /// <summary>
        /// Gets or sets the web service parameters.
        /// </summary>
        /// <value>The web service parameters.</value>
        public WebServiceParameters WebServiceParameters { get; set; }

        /// <summary>
        /// Clears the linked connection credentials.
        /// </summary>
        public static void ClearCredentials(TridentConnection connection)
        {
            if (connection != null)
            {
                if (connection.ConnectionType == ConnectionType.Sql)
                {
                    connection.SqlParameters.Password = string.Empty;
                }
                else if (connection.ConnectionType == ConnectionType.WebService)
                {
                    connection.WebServiceParameters.Password = string.Empty;
                }
            }
        }
    }
}
